package com.nix.web.databases.jdbc.core;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;


import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 从spring中获取数据源
 * Create by zhangpe0312@qq.com on 2017/12/21.
 */
@Service
public class JdbcDataSources {
    /**
     * 获取JDBC数据源
     *
     * @return
     */
    public DataSource getDataSource() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("application.xml");
        return (DataSource) context.getBean("dataSource");
    }

    public static void main(String[] args) {
//        JdbcDataSources dataSources = new JdbcDataSources();
//        System.out.println( dataSources.getDataSource());
//        try {
//            Connection connection =  dataSources.getDataSource().getConnection();
//            System.out.println(connection);
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
        String value = "an1 fen4 shou3 ji3";
        System.out.println(value.length());
    }
}
